package com.china08.yxyapi.api.manage.sch.office.innernotice;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.api.YxyApiBaseController;
import com.china08.yxyapi.model.YxyApiRespModel;
import com.china08.yxyapi.repository.mg.YxyNoticeInnerRepository;

/**
 * 学校管理员 收件箱 查询收件箱未读数
 * 
 */
@CrossOrigin
@RestController("SchInnerNoticeFindNoReadCountController")
public class InnerNoticeFindNoReadCountController extends YxyApiBaseController {

    @Autowired
    private YxyNoticeInnerRepository yxyNoticeInnerRepository;

    @RequestMapping(value = "/api_yw/manage/sch/office/innerNotice/receive/noReadCount", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public Object precess(HttpServletRequest request, HttpServletResponse response) {
        String schoolId = getProfile(request, response).getSchoolId();
        String currentUserId = getProfile(request, response).getId();
        Integer count = yxyNoticeInnerRepository.SchoolIdAndReceiverUserIdAndReceiverIsDeleteAndReceiverIsRead(schoolId,
                currentUserId, 0, 0);
        RespModel respModel = new RespModel();
        respModel.setCount(count);
        return respModel;
    }

    protected static class RespModel extends YxyApiRespModel {

        private int count;

        public int getCount() {
            return count;
        }

        public void setCount(int count) {
            this.count = count;
        }
    }
}